-- ================================================
-- Template generated from Template Explorer using:
-- Create Procedure (New Menu).SQL
--
-- Use the Specify Values for Template Parameters 
-- command (Ctrl-Shift-M) to fill in the parameter 
-- values below.
--
-- This block of comments will not be included in
-- the definition of the procedure.
-- ================================================
USE RealEstate
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author:		<Author,,Name>
-- Create date: <Create Date,,>
-- Description:	<Description,,>
-- =============================================
CREATE PROCEDURE dbo.sp_createUser
	-- Add the parameters for the stored procedure here
	@userName varchar(50),
	@userPassword varchar(255),
	@firstName varchar(50),
	@lastName varchar(50),
	@address varchar(50),
	@phone varchar(50),
	@email varchar(50),
	@birth datetime,
	@genre varchar(10)
AS
BEGIN
	INSERT INTO Users VALUES(
	@userName, 
	@userPassword,
	@firstName, 
	@lastName, 
	@address, 
	@phone, 
	@email, 
	@birth, 
	@genre)
END
GO
--test CreateUser--
exec sp_createUser  
@userName='232323', 
@userPassword='123', 
@firstName=NULL, 
@lastName=NULL,
@address=NULL,
@phone=NULL, 
@email = NULL,
@birth=NULL,
@genre=NULL

--READALL--
CREATE PROC dbo.sp_selectAllUser

AS
BEGIN
	SELECT * FROM Users 
END

--testReadAll
exec sp_selectAllUser

--READBYID--
CREATE PROC dbo.sp_selectUserByName
@userName varchar
AS
BEGIN
	SELECT * FROM Users WHERE userName =  @userName
END
--testReadByID
exec sp_selectUserByName '1234'

--DELETE--
CREATE PROC dbo.sp_DeleteUser
@userID int
AS
BEGIN
	DELETE FROM Users WHERE userID=@userID
END
--testDELETE
exec sp_deleteUser @userID=3

--UPDATE--
CREATE PROC dbo.sp_UpdateUser
	@userName varchar(50),
	@userPassword varchar(255),
	@firstName varchar(50),
	@lastName varchar(50),
	@address varchar(50),
	@phone varchar(50),
	@email varchar(50),
	@birth datetime,
	@genre varchar(10)
AS
BEGIN
	UPDATE Users SET 
	firstName = @firstName,
	lastName = @lastName,
	address =@address,
	phone = @phone,
	email = @email,
	birth = @birth,
	genre = @genre
	WHERE userID=@userID
END
--test Update
exec sp_UpdateUser 
@userName=4, 
@userPassword='123', 
@firstName=Bow, 
@lastName=Fox,
@address= '23 Downinh',
@phone=4343, 
@email = 'abc@gmail.com',
@birth='1992-12-20',
@genre= 'male'